package in.ac.dei.edrp.cms.controller.studentregistration;

import in.ac.dei.edrp.cms.dao.studentregistration.CheckDuplicateStudentDAO;
import in.ac.dei.edrp.cms.dao.studentregistration.StudentVerificationDao;
import in.ac.dei.edrp.cms.domain.studentregistration.StudentInfoGetter;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class CheckDuplicateStudentController extends MultiActionController {

	private CheckDuplicateStudentDAO checkDuplicateStudentDao;

    /**
     * Method to initialize controller
     * @param studentVerification
     */
    public void setCheckDuplicateStudentDAO(CheckDuplicateStudentDAO checkDuplicateStudentDao) {
        this.checkDuplicateStudentDao = checkDuplicateStudentDao;
    }
 
    /**
     * this method will check the registered duplicate student
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView getDuplicateStudent(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    	HttpSession session = request.getSession(true);
    	String universityId =(String) session.getAttribute("universityId");
		if(universityId == null)
		{
			return new ModelAndView("general/SessionInactive","sessionInactive",true);
		}
        
		StudentInfoGetter studentInfoGetter = new StudentInfoGetter();
		studentInfoGetter.setUniversityId(universityId);
		studentInfoGetter.setCreatorId(session.getAttribute("userId").toString());
		System.out.println("Inside Controller: "+ universityId);
		
        List<StudentInfoGetter> studentList = new ArrayList<StudentInfoGetter>();    
        boolean flag = checkDuplicateStudentDao.findDuplicateStudent(studentInfoGetter);
        
        if(flag){
        	List<StudentInfoGetter> duplicateStudent = checkDuplicateStudentDao.getDuplicateStudentList(studentInfoGetter);        	
        	return new ModelAndView("studentregistration/DuplicateStudentList","duplicateStudent", duplicateStudent);
        }
        else{
        	return new ModelAndView("activitymaster/InsertionInfo","message", "NotFound");
        }
        
    }
    
    
    /**
     * Method for generate the PDF.
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
	public ModelAndView generatePDF(HttpServletRequest request,
			HttpServletResponse response)throws Exception {
		HttpSession session = request.getSession(true);
    	String universityId =(String) session.getAttribute("universityId");
		if(universityId == null)
		{
			return new ModelAndView("general/SessionInactive","sessionInactive",true);
		}
		
		StudentInfoGetter studentInfoGetter = new StudentInfoGetter();
		studentInfoGetter.setUniversityId(universityId);
		
		List<StudentInfoGetter> duplicateStudentList = checkDuplicateStudentDao.getDuplicateStudentList(studentInfoGetter);
		
		return new ModelAndView("DuplicateStudentListPDFView","duplicateStudentList", duplicateStudentList);		
	}
	
	   /**
     * Method for generate the PDF.
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
	public ModelAndView getGeneratedDuplicateStudent(HttpServletRequest request,
			HttpServletResponse response)throws Exception {
		HttpSession session = request.getSession(true);
    	String universityId =(String) session.getAttribute("universityId");
		if(universityId == null){
			return new ModelAndView("general/SessionInactive","sessionInactive",true);
		}
		
		StudentInfoGetter studentInfoGetter = new StudentInfoGetter();
		studentInfoGetter.setUniversityId(universityId);
		
		List<StudentInfoGetter> duplicateStudentList = checkDuplicateStudentDao.getDuplicateStudentList(studentInfoGetter);
		return new ModelAndView("studentregistration/DuplicateStudentList","duplicateStudent", duplicateStudentList);		
	}
	
	   /**
     * Method for generate the PDF.
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
	public ModelAndView checkProcessStatus(HttpServletRequest request,
			HttpServletResponse response)throws Exception {
		HttpSession session = request.getSession(true);
    	String universityId =(String) session.getAttribute("universityId");
		if(universityId == null){
			return new ModelAndView("general/SessionInactive","sessionInactive",true);
		}
		
		StudentInfoGetter studentInfoGetter = new StudentInfoGetter();
		studentInfoGetter.setUniversityId(universityId);
		
		String status = checkDuplicateStudentDao.getProcessStatus(studentInfoGetter);
		return new ModelAndView("activitymaster/InsertionInfo","message", status);
	}
	
	   /**
     * Method for generate the PDF.
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
	public ModelAndView getSessionDetail(HttpServletRequest request,
			HttpServletResponse response)throws Exception {
		HttpSession session = request.getSession(true);
    	String universityId =(String) session.getAttribute("universityId");
		if(universityId == null){
			return new ModelAndView("general/SessionInactive","sessionInactive",true);
		}
		
		StudentInfoGetter studentInfoGetter = new StudentInfoGetter();
		studentInfoGetter.setUniversityId(universityId);
		studentInfoGetter.setSessionStartDate(session.getAttribute("startDate").toString());
		studentInfoGetter.setSessionEndDate(session.getAttribute("endDate").toString());
		List<StudentInfoGetter> list= new ArrayList<StudentInfoGetter>();
		list.add(studentInfoGetter);
		return new ModelAndView("activitymaster/SessionDetails","sessionDetails", list);
	}

}
